package com.jms.activemq;

import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

/**
 * @author xiangui
 * 描述: 消息订阅者1
 * 时间: Create in 19:03 2018/7/24
 */
public class JMSCunsumer {

    private static final String USERNAME = ActiveMQConnection.DEFAULT_USER;

    private static final String PASSWORD = ActiveMQConnection.DEFAULT_PASSWORD;

    private static final String BROKENURL = ActiveMQConnection.DEFAULT_BROKER_URL;

    public static void main(String[] args) {

        ConnectionFactory connectionFactory;

        Connection connection = null;

        Session session;

        Destination destination;

        MessageConsumer messageConsumer;


        connectionFactory = new ActiveMQConnectionFactory(JMSCunsumer.USERNAME, JMSCunsumer.PASSWORD, JMSCunsumer.BROKENURL);

        try {
            connection = connectionFactory.createConnection();
            connection.start();
            session = connection.createSession(Boolean.FALSE, Session.AUTO_ACKNOWLEDGE);
            destination = session.createTopic("FirstTopic");
            messageConsumer = session.createConsumer(destination); //创建消费者
            messageConsumer.setMessageListener(new Listener());
        } catch (JMSException e) {
            e.printStackTrace();
        }


    }

}
